home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / hyper / hsc_source.lha / hsc / source / ugly / ufile.c < prev    next >
C/C++ Source or Header  |  1996-10-15  |  2KB  |  80 lines

  1. /*
  2.  * ugly/ufile.c
  3.  *
  4.  * misc. filename functions
  5.  *
  6.  * Copyright (C) 1996  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated: 15-Oct-1996
  23.  * created: 14-Oct-1996
  24.  *
  25.  *-------------------------------------------------------------------
  26.  *
  27.  */
  28.  
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include "utypes.h"
  34. #include "umemory.h"
  35. #include "ustring.h"
  36. #include "expstr.h"
  37.  
  38. #define NOEXTERN_UGLY_UFILE_H
  39. #include "ufile.h"
  40.  
  41. /*
  42.  * fexists
  43.  *
  44.  * check if file exists ( = could have been opened for input)
  45.  *
  46.  * result: TRUE, if file exists, else FALSE
  47.  *
  48.  */
  49. BOOL fexists( STRPTR filename)
  50. {
  51.     FILE *file = fopen( filename, "r");
  52.     if (file)
  53.     {
  54.         fclose(file);
  55.     }
  56.     return((BOOL)(file!=NULL));
  57. }
  58.  
  59. /*
  60.  * getfsize
  61.  *
  62.  * get size of file
  63.  *
  64.  * parans: filename...path and name of file to examine
  65.  * result: size of file
  66.  */
  67. LONG getfsize( STRPTR filename)
  68. {
  69.     FILE *file = fopen(filename, "rb");
  70.     LONG filesize = 0;
  71.     if (file)
  72.     {
  73.         /* retrieve size */
  74.         fseek(file, 0L, SEEK_END);
  75.         filesize = ftell(file);
  76.         fclose(file);
  77.     }
  78.     return(filesize);
  79. }
  80.